<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	HttpServletRequest r = request;
	String path = r.getContextPath();
	String basePath = r.getScheme() + "://" + r.getServerName() + ":" + r.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<input type="button" onclick="date()" value="按钮">
	<div style="width: 100px; height: 100px; border: 4px solid black;"
		id="a">aaa</div>

	<script type="text/javascript">
		function date() {
			var ajax;
			if (window.XMLHttpRequest) {//火狐
				ajax = new XMLHttpRequest();
			} else if (window.ActiveXObject) {//IE
				ajax = new ActiveXObject("Msxml2.XMLHTTP");
			}
			// 复写onreadystatechange函数
			ajax.onreadystatechange = function() {
				// 判断Ajax状态码
				if (ajax.readyState == 4) {
					// 判读响应状态码 
					if (ajax.statue == 200) {
						// 获取响应内容
						var result = ajax.responseText;
						//处理响应
						var show = document.getElementById("a");
						show.innerHTML = result;
					} else if (ajax.status == 404) {
						var show = document.getElementById("a");
						show.innerHTML = "请求资源不存在";
					} else if (ajax.status == 500) {
						var show = document.getElementById("a");
						show.innerHTML = "服务器繁忙！！请稍后请求。。。";
					}
				}else{
					// 在请求成功之前可先执行其他操作，例如等待图片
				}
			}
			// 请求方式及地址，并发送
			ajax.open("get", "ajax");
			ajax.send(null);

			alert("jjj");
		}
	</script>
</body>
</html>